function tongBu(scene, physicsAddMesh, physicsDeleteMesh, physicsSetMeshPosition, jueSeHao, jueSeObj, physicsMeshes,
	shuaXinUI, ws, jueSeWo) {

	this.wuTiArr = [];
	this.shiJian = 0;
	this.shiJianYiYong = [];

	this.tianJia = function(a) {
		scene.add(a.mesh)
		physicsAddMesh(a.mesh, a.zhiLiang);
		physicsSetMeshPosition(a.mesh, a.weiZhi, a.suDu);
		this.wuTiArr.push(a)
	}

	let _this = this;

	ws.addEventListener('message', function(evt) {
		let jieGuo = JSON.parse(evt.data);
		_this.wuTiArr = jieGuo.xinXiArr;
		_this.shiJian = jieGuo.shiJian;
		
		if (jieGuo.jiShaXinXi != '') {
			shuaXinUI(jueSeWo.userData.xueLiang, jieGuo.jiShaXinXi);
		};
	})

	this.shuaXin = function() {

		//已接受过的服务端数据不再刷新
		if (!_this.shiJianYiYong.includes(_this.shiJian)) {

			_this.shiJianYiYong.push(_this.shiJian);

			let wuTiArr = [..._this.wuTiArr]; //scene.add会改变数组 浅拷贝一下
			let webJueSeHao = [];

			for (let i = 0; i < wuTiArr.length; i++) {

				let webObj = wuTiArr[i];

				if (!webObj.jueSeHao) continue;

				webJueSeHao.push(webObj.jueSeHao);

				let benDiObj = jueSeObj.get(webObj.jueSeHao);

				if (!physicsMeshes.includes(benDiObj)) {

					scene.add(benDiObj);
					physicsAddMesh(benDiObj, 80, 'Compound');

				} else {

					if (benDiObj.userData.jueSeHao === jueSeHao) {

						if (webObj.woBeiDaJi.length > 0) {

							for (let i = 0; i < webObj.woBeiDaJi.length; i++) {
								let xueLiang = benDiObj.userData.xueLiang - webObj.woBeiDaJi[i].shangHai;
								benDiObj.userData.xueLiang = xueLiang > 0 ? xueLiang : 0;

								shuaXinUI(benDiObj.userData.xueLiang)

								//本人死亡
								if (benDiObj.userData.xueLiang === 0) {

									let xinXi = {
										leiXing: 'jiShaXinXi',
										neiRong: `${webObj.woBeiDaJi[i].jueSeHao}号玩家 击杀了 ${benDiObj.userData.jueSeHao}号玩家`
									};

									ws.send(JSON.stringify(xinXi));

									benDiObj.position.copy(benDiObj.userData.chuShengDian);
									physicsSetMeshPosition(benDiObj, benDiObj.userData.chuShengDian, undefined,
										undefined);

									benDiObj.userData.xueLiang = 100;
									shuaXinUI(benDiObj.userData.xueLiang);

									break;
								}
							}

						}

						continue; //本人不同步位置
					}

					let position = new THREE.Vector3(webObj.weiZhi.x, webObj.weiZhi.y, webObj.weiZhi.z);
					let quaternion = new THREE.Quaternion(webObj.xuanZhuan.x, webObj.xuanZhuan.y, webObj.xuanZhuan
						.z,
						webObj.xuanZhuan.w);
					let niuZhuanQuaternion = new THREE.Quaternion(webObj.niuZhuan.x, webObj.niuZhuan.y, webObj
						.niuZhuan.z,
						webObj.niuZhuan.w);

					if (webObj.dongZuo == 'zhan') {
						benDiObj.userData.dongZuo.pao.stop();
						benDiObj.userData.dongZuo.zhan.play();
					}
					if (webObj.dongZuo == 'pao') {
						benDiObj.userData.dongZuo.zhan.stop();
						benDiObj.userData.dongZuo.pao.play();
					}
					benDiObj.quaternion.copy(quaternion);
					benDiObj.position.copy(position);
					benDiObj.userData.xiongBone.quaternion.copy(niuZhuanQuaternion);

					physicsSetMeshPosition(benDiObj, position, undefined, undefined);
				}

			}
			
			//删除退出的角色
			jueSeObj.forEach(obj => {

				if (webJueSeHao.length > 0 && !webJueSeHao.includes(obj.userData.jueSeHao) && physicsMeshes
					.includes(obj) && obj.userData.wo === undefined) {

					scene.remove(obj);
					physicsDeleteMesh(obj);
				}
			})
		}

	}
}

export default tongBu;
